package sanrenxing.dayEnd.backRepertoryTotal.dao;


import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import sanrenxing.dayEnd.backRepertoryTotal.domain.Fun;
import sanrenxing.dayEnd.backRepertoryTotal.domain.Rf;
import sanrenxing.dayEnd.backRepertoryTotal.domain.Role;
import sanrenxing.dayEnd.backRepertoryTotal.domain.users;

import java.util.List;

@Repository
public interface FunD {
    @Select("SELECT DISTINCT * FROM fun WHERE funId IN(SELECT DISTINCT funId FROM rf WHERE roleId=#{roleId}) OR funId in (SELECT DISTINCT funparentId  FROM fun WHERE funId IN (SELECT DISTINCT funId FROM rf WHERE roleId=#{roleId})) OR funparentId  IN (SELECT DISTINCT funId FROM rf WHERE roleId=#{roleId})")
    public List<Fun> all(users us);
    @Select("select roleId,roleName from (select rownum r,role.* from role where rownum<=${limit}) where r>=${page}")
    public List<Role> rall(@Param("limit") int limit, @Param("page") int page);
    @Insert("insert into role values(#{roleId},#{roleName})")
    @SelectKey(statement = "select roles.nextval from dual", keyColumn = "roleId",keyProperty ="roleId" , before = true, resultType =Integer.class )
    public int add(Role us);
    @Delete("delete from role where roleId=#{roleId}")
    public int del(int us);
    @Update("update role set roleName=#{roleName} where roleId=#{roleId}")
    public int update(Role us);
    @Select("select count(*) from role")
    public int count();
    @Select("select * from rf where roleId=${roleId}")
    public List<Rf> rfal(int ss);

    @Delete("delete from rf where roleId=#{roleId}")
    public int rdel(int us);
    @Insert("insert into rf values(#{roleId},#{funId})")
    public int radd(Rf us);
}
